<template>
  <div class="supplier-product-box">
    <img :src="productDetail.image" alt="">
    <i style="position: absolute; top: 5px; right: 5px; font-size: 18px" class="el-icon-document-copy" @click="copyProductLink"></i>
    <div class="product-name">
      <span class="ovd_s" v-text="productDetail.name"></span>
    </div>
    <div class="product-price">
      <span class="price" v-text="'￥'+ToMoney(productDetail.price)"></span>
      <span class="supplier-name" v-text="productDetail.supplierName" @click="$router.push({
      path:'/SupplierProductSearchPage',
      query:{
        supplierId:productDetail.supplierId
      }
      })"></span>
    </div>
    <div class="product-model">
      <div class="model">
        <div style="float: left; width: 26%;">型号:</div>
        <div style="float: left; width: 74%; text-align: left">
          <span style="display: inline-block; max-width: 118px; height: 20px; line-height: 20px;" class="ovd_s" v-text="productDetail.supplierProductStockModel?productDetail.supplierProductStockModel:'常规'" :title="productDetail.supplierProductStockModel?productDetail.supplierProductStockModel:'常规'"></span>
        </div>
        <div class="c"></div>
      </div>
      <div class="add-cart">
          <my-button type="danger" :click="function (){addCart()}" text="加入购物车" access-action="SupplierOrder/manage"></my-button>
      </div>
    </div>

  </div>
</template>

<script>


import MyButton from './MyButton'
export default {
  name: 'SupplierProductBox',
  components: {MyButton},
  props:{
    productDetail:Object
  },
  methods:{
    copyProductLink:function () {
      let $this=this
      this.$copyText('【可可商城-店铺系统】'+this.$props.productDetail.name+(this.$props.productDetail.supplierProductStockModel!=='常规'?' '+this.$props.productDetail.supplierProductStockModel:'')+' '+location.protocol+'//'+location.host+'/#/SupplierProductSearchPage?id='+$this.$props.productDetail.supplierProductStockId).then(
        e=>{
          $this.$message.success('复制商品信息成功')
        },
        e=>{
          console.log('复制失败：', e);
        }
      )
    },
    addCart:function () {
      let $this=this
      if (this.$props.productDetail.isMoreModel){
        $this.bus.$emit('ProductChooseModelDialogCallBus','productListItem',$this.$props.productDetail)
      }else{
        $this.$message.success('添加购物车成功')
        window.MyCartTools.addProduct({
          id: $this.$props.productDetail.supplierProductStockId,
          productId: $this.$props.productDetail.id,
          name: $this.$props.productDetail.name,
          image: $this.$props.productDetail.image,
          supplierId: $this.$props.productDetail.supplierId,
          supplierName: $this.$props.productDetail.supplierName,
          supplierLogo: $this.$props.productDetail.supplierLogo,
          nums: 1,
          price: $this.$props.productDetail.price,
          model: $this.$props.productDetail.supplierProductStockModel,
        })

        console.log('$this.$props.productDetail',$this.$props.productDetail)
        //
        // window.MyCartTools.addProduct(Object.assign($this.$props.productDetail,{
        //   nums:1,
        //   model:'常规'
        // }))
      }
    }
  }
}
</script>

<style scoped>

</style>
